import sys

sys.path.append('../')

from config import *


@app.route('/platform_account_info.do', methods = ['GET'])
def platform_account_info():
    if not 'username' in session:
        return redirect(url_for('login'))

    accountName = request.args.get('accountName', '').strip()
    accountPwd = request.args.get('accountPwd', '').strip()
    platform = request.args.get('platform', '').strip()

    if not accountName or not accountPwd:
        resp = {
            'success': False,
            'msg': '账号名称和密码都不能为空'
        }

        response = make_response(jsonify(resp))
        return response

    user = qushu_cv_match_user_coll.find_one({'uid': session['uid']})

    if not 'platform_accounts' in user:
        platform_accounts = {}
    else:
        platform_accounts = user['platform_accounts']

    platform_accounts[platform] = {
        'accountName': accountName,
        'accountPwd': accountPwd
    }

    qushu_cv_match_user_coll.update_one({'uid': session['uid']}, {'$set': {'platform_accounts': platform_accounts}})

    resp = {
        'success': True,
        'msg': '成功绑定!'
    }

    response = make_response(jsonify(resp))
    return response
